package com.itheima.edu.controller.impl;


import com.itheima.edu.domain.Teacher;
import com.itheima.edu.uitls.AgeUtils;

public class TeacherController extends BasePersonController<Teacher> {
    @Override
    public void addPerson(String msg) {
        System.out.println("请输入添加的" + msg + "编号:");
        String id = sc.nextLine();
        int index = personService.getIndexById(id);
        if (index == -1) {
            System.out.println("请输入要添加的" +msg + "姓名");
            String name = sc.nextLine();
            String birthday , age;
            System.out.println("请输入要添加的" + msg + "生日");
            birthday = sc.nextLine();
            age = AgeUtils.getAge(birthday);
            if (age.equals("-1")){
                System.out.println("日期格式有误,添加失败");
                return;
            }
            personService.addPerson(new Teacher(id,name,age,birthday));

        }else {
            System.out.println("当前编号已存在,无法执行添加操作");
        }
    }

    @Override
    public void updatePerson(String msg) {
        System.out.println("请输入修改的" + msg + "编号:");
        String id = sc.nextLine();
        int index = personService.getIndexById(id);
        if (index != -1) {
            System.out.println("请输入要修改的"+ msg + "姓名");
            String name = sc.nextLine();
            String birthday , age;
            System.out.println("请输入要添加的"+msg + "生日");
            birthday = sc.nextLine();
            age = AgeUtils.getAge(birthday);
            if (age.equals("-1")){
                System.out.println("日期格式有误,修改失败");
                return;
            }
            personService.updatePerson(index,new Teacher(id,name,age,birthday));

        }else {
            System.out.println("当前编号不存在,无法执行修改操作");
        }
    }

}
